<html>
  <head>
  <title>graphicsDisplay.py</title>
  </head>
  <body>
  <h3>graphicsDisplay.py (<a href="../graphicsDisplay.py">original</a>)</h3>
  <hr>
  <pre>
<span style="color: green; font-style: italic"># graphicsDisplay.py
# ------------------
# Licensing Information: Please do not distribute or publish solutions to this
# project. You are free to use and extend these projects for educational
# purposes. The Pacman AI projects were developed at UC Berkeley, primarily by
# John DeNero (denero@cs.berkeley.edu) and Dan Klein (klein@cs.berkeley.edu).
# For more info, see http://inst.eecs.berkeley.edu/~cs188/sp09/pacman.html

</span><span style="color: blue; font-weight: bold">from </span>graphicsUtils <span style="color: blue; font-weight: bold">import </span><span style="font-weight: bold">*
</span><span style="color: blue; font-weight: bold">import </span>math<span style="font-weight: bold">, </span>time
<span style="color: blue; font-weight: bold">from </span>game <span style="color: blue; font-weight: bold">import </span>Directions

<span style="color: green; font-style: italic">###########################
#  GRAPHICS DISPLAY CODE  #
###########################

# Most code by Dan Klein and John Denero written or rewritten for cs188, UC Berkeley.
# Some code from a Pacman implementation by LiveWires, and used / modified with permission.

</span>DEFAULT_GRID_SIZE <span style="font-weight: bold">= </span><span style="color: red">30.0
</span>INFO_PANE_HEIGHT <span style="font-weight: bold">= </span><span style="color: red">35
</span>BACKGROUND_COLOR <span style="font-weight: bold">= </span>formatColor<span style="font-weight: bold">(</span><span style="color: red">0</span><span style="font-weight: bold">,</span><span style="color: red">0</span><span style="font-weight: bold">,</span><span style="color: red">0</span><span style="font-weight: bold">)
</span>WALL_COLOR <span style="font-weight: bold">= </span>formatColor<span style="font-weight: bold">(</span><span style="color: red">0.0</span><span style="font-weight: bold">/</span><span style="color: red">255.0</span><span style="font-weight: bold">, </span><span style="color: red">51.0</span><span style="font-weight: bold">/</span><span style="color: red">255.0</span><span style="font-weight: bold">, </span><span style="color: red">255.0</span><span style="font-weight: bold">/</span><span style="color: red">255.0</span><span style="font-weight: bold">)
</span>INFO_PANE_COLOR <span style="font-weight: bold">= </span>formatColor<span style="font-weight: bold">(.</span><span style="color: red">4</span><span style="font-weight: bold">,.</span><span style="color: red">4</span><span style="font-weight: bold">,</span><span style="color: red">0</span><span style="font-weight: bold">)
</span>SCORE_COLOR <span style="font-weight: bold">= </span>formatColor<span style="font-weight: bold">(.</span><span style="color: red">9</span><span style="font-weight: bold">, .</span><span style="color: red">9</span><span style="font-weight: bold">, .</span><span style="color: red">9</span><span style="font-weight: bold">)
</span>PACMAN_OUTLINE_WIDTH <span style="font-weight: bold">= </span><span style="color: red">2
</span>PACMAN_CAPTURE_OUTLINE_WIDTH <span style="font-weight: bold">= </span><span style="color: red">4

</span>GHOST_COLORS <span style="font-weight: bold">= []
</span>GHOST_COLORS<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>formatColor<span style="font-weight: bold">(.</span><span style="color: red">9</span><span style="font-weight: bold">,</span><span style="color: red">0</span><span style="font-weight: bold">,</span><span style="color: red">0</span><span style="font-weight: bold">)) </span><span style="color: green; font-style: italic"># Red
</span>GHOST_COLORS<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>formatColor<span style="font-weight: bold">(</span><span style="color: red">0</span><span style="font-weight: bold">,.</span><span style="color: red">3</span><span style="font-weight: bold">,.</span><span style="color: red">9</span><span style="font-weight: bold">)) </span><span style="color: green; font-style: italic"># Blue
</span>GHOST_COLORS<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>formatColor<span style="font-weight: bold">(.</span><span style="color: red">98</span><span style="font-weight: bold">,.</span><span style="color: red">41</span><span style="font-weight: bold">,.</span><span style="color: red">07</span><span style="font-weight: bold">)) </span><span style="color: green; font-style: italic"># Orange
</span>GHOST_COLORS<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>formatColor<span style="font-weight: bold">(.</span><span style="color: red">1</span><span style="font-weight: bold">,.</span><span style="color: red">75</span><span style="font-weight: bold">,.</span><span style="color: red">7</span><span style="font-weight: bold">)) </span><span style="color: green; font-style: italic"># Green
</span>GHOST_COLORS<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>formatColor<span style="font-weight: bold">(</span><span style="color: red">1.0</span><span style="font-weight: bold">,</span><span style="color: red">0.6</span><span style="font-weight: bold">,</span><span style="color: red">0.0</span><span style="font-weight: bold">)) </span><span style="color: green; font-style: italic"># Yellow
</span>GHOST_COLORS<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>formatColor<span style="font-weight: bold">(.</span><span style="color: red">4</span><span style="font-weight: bold">,</span><span style="color: red">0.13</span><span style="font-weight: bold">,</span><span style="color: red">0.91</span><span style="font-weight: bold">)) </span><span style="color: green; font-style: italic"># Purple

</span>TEAM_COLORS <span style="font-weight: bold">= </span>GHOST_COLORS<span style="font-weight: bold">[:</span><span style="color: red">2</span><span style="font-weight: bold">]

</span>GHOST_SHAPE <span style="font-weight: bold">= [
    ( </span><span style="color: red">0</span><span style="font-weight: bold">,    </span><span style="color: red">0.3 </span><span style="font-weight: bold">),
    ( </span><span style="color: red">0.25</span><span style="font-weight: bold">, </span><span style="color: red">0.75 </span><span style="font-weight: bold">),
    ( </span><span style="color: red">0.5</span><span style="font-weight: bold">,  </span><span style="color: red">0.3 </span><span style="font-weight: bold">),
    ( </span><span style="color: red">0.75</span><span style="font-weight: bold">, </span><span style="color: red">0.75 </span><span style="font-weight: bold">),
    ( </span><span style="color: red">0.75</span><span style="font-weight: bold">, -</span><span style="color: red">0.5 </span><span style="font-weight: bold">),
    ( </span><span style="color: red">0.5</span><span style="font-weight: bold">,  -</span><span style="color: red">0.75 </span><span style="font-weight: bold">),
    (-</span><span style="color: red">0.5</span><span style="font-weight: bold">,  -</span><span style="color: red">0.75 </span><span style="font-weight: bold">),
    (-</span><span style="color: red">0.75</span><span style="font-weight: bold">, -</span><span style="color: red">0.5 </span><span style="font-weight: bold">),
    (-</span><span style="color: red">0.75</span><span style="font-weight: bold">, </span><span style="color: red">0.75 </span><span style="font-weight: bold">),
    (-</span><span style="color: red">0.5</span><span style="font-weight: bold">,  </span><span style="color: red">0.3 </span><span style="font-weight: bold">),
    (-</span><span style="color: red">0.25</span><span style="font-weight: bold">, </span><span style="color: red">0.75 </span><span style="font-weight: bold">)
  ]
</span>GHOST_SIZE <span style="font-weight: bold">= </span><span style="color: red">0.65
</span>SCARED_COLOR <span style="font-weight: bold">= </span>formatColor<span style="font-weight: bold">(</span><span style="color: red">1</span><span style="font-weight: bold">,</span><span style="color: red">1</span><span style="font-weight: bold">,</span><span style="color: red">1</span><span style="font-weight: bold">)

</span>GHOST_VEC_COLORS <span style="font-weight: bold">= </span>map<span style="font-weight: bold">(</span>colorToVector<span style="font-weight: bold">, </span>GHOST_COLORS<span style="font-weight: bold">)

</span>PACMAN_COLOR <span style="font-weight: bold">= </span>formatColor<span style="font-weight: bold">(</span><span style="color: red">255.0</span><span style="font-weight: bold">/</span><span style="color: red">255.0</span><span style="font-weight: bold">,</span><span style="color: red">255.0</span><span style="font-weight: bold">/</span><span style="color: red">255.0</span><span style="font-weight: bold">,</span><span style="color: red">61.0</span><span style="font-weight: bold">/</span><span style="color: red">255</span><span style="font-weight: bold">)
</span>PACMAN_SCALE <span style="font-weight: bold">= </span><span style="color: red">0.5
</span><span style="color: green; font-style: italic">#pacman_speed = 0.25

# Food
</span>FOOD_COLOR <span style="font-weight: bold">= </span>formatColor<span style="font-weight: bold">(</span><span style="color: red">1</span><span style="font-weight: bold">,</span><span style="color: red">1</span><span style="font-weight: bold">,</span><span style="color: red">1</span><span style="font-weight: bold">)
</span>FOOD_SIZE <span style="font-weight: bold">= </span><span style="color: red">0.1

</span><span style="color: green; font-style: italic"># Laser
</span>LASER_COLOR <span style="font-weight: bold">= </span>formatColor<span style="font-weight: bold">(</span><span style="color: red">1</span><span style="font-weight: bold">,</span><span style="color: red">0</span><span style="font-weight: bold">,</span><span style="color: red">0</span><span style="font-weight: bold">)
</span>LASER_SIZE <span style="font-weight: bold">= </span><span style="color: red">0.02

</span><span style="color: green; font-style: italic"># Capsule graphics
</span>CAPSULE_COLOR <span style="font-weight: bold">= </span>formatColor<span style="font-weight: bold">(</span><span style="color: red">1</span><span style="font-weight: bold">,</span><span style="color: red">1</span><span style="font-weight: bold">,</span><span style="color: red">1</span><span style="font-weight: bold">)
</span>CAPSULE_SIZE <span style="font-weight: bold">= </span><span style="color: red">0.25

</span><span style="color: green; font-style: italic"># Drawing walls
</span>WALL_RADIUS <span style="font-weight: bold">= </span><span style="color: red">0.15

</span><span style="color: blue; font-weight: bold">class </span>InfoPane<span style="font-weight: bold">:
  </span><span style="color: blue; font-weight: bold">def </span>__init__<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>layout<span style="font-weight: bold">, </span>gridSize<span style="font-weight: bold">):
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize <span style="font-weight: bold">= </span>gridSize
    <span style="color: blue">self</span><span style="font-weight: bold">.</span>width <span style="font-weight: bold">= (</span>layout<span style="font-weight: bold">.</span>width<span style="font-weight: bold">) * </span>gridSize
    <span style="color: blue">self</span><span style="font-weight: bold">.</span>base <span style="font-weight: bold">= (</span>layout<span style="font-weight: bold">.</span>height <span style="font-weight: bold">+ </span><span style="color: red">1</span><span style="font-weight: bold">) * </span>gridSize
    <span style="color: blue">self</span><span style="font-weight: bold">.</span>height <span style="font-weight: bold">= </span>INFO_PANE_HEIGHT
    <span style="color: blue">self</span><span style="font-weight: bold">.</span>fontSize <span style="font-weight: bold">= </span><span style="color: red">24
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>textColor <span style="font-weight: bold">= </span>PACMAN_COLOR
    <span style="color: blue">self</span><span style="font-weight: bold">.</span>drawPane<span style="font-weight: bold">()

  </span><span style="color: blue; font-weight: bold">def </span>toScreen<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>pos<span style="font-weight: bold">, </span>y <span style="font-weight: bold">= </span><span style="color: blue">None</span><span style="font-weight: bold">):
    </span><span style="color: darkred">"""
      Translates a point relative from the bottom left of the info pane.
    """
    </span><span style="color: blue; font-weight: bold">if </span>y <span style="font-weight: bold">== </span><span style="color: blue">None</span><span style="font-weight: bold">:
      </span>x<span style="font-weight: bold">,</span>y <span style="font-weight: bold">= </span>pos
    <span style="color: blue; font-weight: bold">else</span><span style="font-weight: bold">:
      </span>x <span style="font-weight: bold">= </span>pos

    x <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize <span style="font-weight: bold">+ </span>x <span style="color: green; font-style: italic"># Margin
    </span>y <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>base <span style="font-weight: bold">+ </span>y
    <span style="color: blue; font-weight: bold">return </span>x<span style="font-weight: bold">,</span>y

  <span style="color: blue; font-weight: bold">def </span>drawPane<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">):
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>scoreText <span style="font-weight: bold">= </span>text<span style="font-weight: bold">( </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>toScreen<span style="font-weight: bold">(</span><span style="color: red">0</span><span style="font-weight: bold">, </span><span style="color: red">0  </span><span style="font-weight: bold">), </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>textColor<span style="font-weight: bold">, </span><span style="color: red">"SCORE:    0"</span><span style="font-weight: bold">, </span><span style="color: red">"Times"</span><span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>fontSize<span style="font-weight: bold">, </span><span style="color: red">"bold"</span><span style="font-weight: bold">)

  </span><span style="color: blue; font-weight: bold">def </span>initializeGhostDistances<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>distances<span style="font-weight: bold">):
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>ghostDistanceText <span style="font-weight: bold">= []

    </span>size <span style="font-weight: bold">= </span><span style="color: red">20
    </span><span style="color: blue; font-weight: bold">if </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>width <span style="font-weight: bold">&lt; </span><span style="color: red">240</span><span style="font-weight: bold">:
      </span>size <span style="font-weight: bold">= </span><span style="color: red">12
    </span><span style="color: blue; font-weight: bold">if </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>width <span style="font-weight: bold">&lt; </span><span style="color: red">160</span><span style="font-weight: bold">:
      </span>size <span style="font-weight: bold">= </span><span style="color: red">10

    </span><span style="color: blue; font-weight: bold">for </span>i<span style="font-weight: bold">, </span>d <span style="color: blue; font-weight: bold">in </span>enumerate<span style="font-weight: bold">(</span>distances<span style="font-weight: bold">):
      </span>t <span style="font-weight: bold">= </span>text<span style="font-weight: bold">( </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>toScreen<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>width<span style="font-weight: bold">/</span><span style="color: red">2 </span><span style="font-weight: bold">+ </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>width<span style="font-weight: bold">/</span><span style="color: red">8 </span><span style="font-weight: bold">* </span>i<span style="font-weight: bold">, </span><span style="color: red">0</span><span style="font-weight: bold">), </span>GHOST_COLORS<span style="font-weight: bold">[</span>i<span style="font-weight: bold">+</span><span style="color: red">1</span><span style="font-weight: bold">], </span>d<span style="font-weight: bold">, </span><span style="color: red">"Times"</span><span style="font-weight: bold">, </span>size<span style="font-weight: bold">, </span><span style="color: red">"bold"</span><span style="font-weight: bold">)
      </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>ghostDistanceText<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>t<span style="font-weight: bold">)

  </span><span style="color: blue; font-weight: bold">def </span>updateScore<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>score<span style="font-weight: bold">):
    </span>changeText<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>scoreText<span style="font-weight: bold">, </span><span style="color: red">"SCORE: % 4d" </span><span style="font-weight: bold">% </span>score<span style="font-weight: bold">)

  </span><span style="color: blue; font-weight: bold">def </span>setTeam<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>isBlue<span style="font-weight: bold">):
    </span>text <span style="font-weight: bold">= </span><span style="color: red">"RED TEAM"
    </span><span style="color: blue; font-weight: bold">if </span>isBlue<span style="font-weight: bold">: </span>text <span style="font-weight: bold">= </span><span style="color: red">"BLUE TEAM"
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>teamText <span style="font-weight: bold">= </span>text<span style="font-weight: bold">( </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>toScreen<span style="font-weight: bold">(</span><span style="color: red">300</span><span style="font-weight: bold">, </span><span style="color: red">0  </span><span style="font-weight: bold">), </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>textColor<span style="font-weight: bold">, </span>text<span style="font-weight: bold">, </span><span style="color: red">"Times"</span><span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>fontSize<span style="font-weight: bold">, </span><span style="color: red">"bold"</span><span style="font-weight: bold">)

  </span><span style="color: blue; font-weight: bold">def </span>updateGhostDistances<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>distances<span style="font-weight: bold">):
    </span><span style="color: blue; font-weight: bold">if </span>len<span style="font-weight: bold">(</span>distances<span style="font-weight: bold">) == </span><span style="color: red">0</span><span style="font-weight: bold">: </span><span style="color: blue; font-weight: bold">return
    if </span><span style="color: red">'ghostDistanceText' </span><span style="color: blue; font-weight: bold">not in </span>dir<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">): </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>initializeGhostDistances<span style="font-weight: bold">(</span>distances<span style="font-weight: bold">)
    </span><span style="color: blue; font-weight: bold">else</span><span style="font-weight: bold">:
      </span><span style="color: blue; font-weight: bold">for </span>i<span style="font-weight: bold">, </span>d <span style="color: blue; font-weight: bold">in </span>enumerate<span style="font-weight: bold">(</span>distances<span style="font-weight: bold">):
        </span>changeText<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>ghostDistanceText<span style="font-weight: bold">[</span>i<span style="font-weight: bold">], </span>d<span style="font-weight: bold">)

  </span><span style="color: blue; font-weight: bold">def </span>drawGhost<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">):
    </span><span style="color: blue; font-weight: bold">pass

  def </span>drawPacman<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">):
    </span><span style="color: blue; font-weight: bold">pass

  def </span>drawWarning<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">):
    </span><span style="color: blue; font-weight: bold">pass

  def </span>clearIcon<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">):
    </span><span style="color: blue; font-weight: bold">pass

  def </span>updateMessage<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>message<span style="font-weight: bold">):
    </span><span style="color: blue; font-weight: bold">pass

  def </span>clearMessage<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">):
    </span><span style="color: blue; font-weight: bold">pass


class </span>PacmanGraphics<span style="font-weight: bold">:
  </span><span style="color: blue; font-weight: bold">def </span>__init__<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>zoom<span style="font-weight: bold">=</span><span style="color: red">1.0</span><span style="font-weight: bold">, </span>frameTime<span style="font-weight: bold">=</span><span style="color: red">0.0</span><span style="font-weight: bold">, </span>capture<span style="font-weight: bold">=</span><span style="color: blue; font-weight: bold">False</span><span style="font-weight: bold">):
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>have_window <span style="font-weight: bold">= </span><span style="color: red">0
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>currentGhostImages <span style="font-weight: bold">= {}
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>pacmanImage <span style="font-weight: bold">= </span><span style="color: blue">None
    self</span><span style="font-weight: bold">.</span>zoom <span style="font-weight: bold">= </span>zoom
    <span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize <span style="font-weight: bold">= </span>DEFAULT_GRID_SIZE <span style="font-weight: bold">* </span>zoom
    <span style="color: blue">self</span><span style="font-weight: bold">.</span>capture <span style="font-weight: bold">= </span>capture
    <span style="color: blue">self</span><span style="font-weight: bold">.</span>frameTime <span style="font-weight: bold">= </span>frameTime

  <span style="color: blue; font-weight: bold">def </span>initialize<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>state<span style="font-weight: bold">, </span>isBlue <span style="font-weight: bold">= </span><span style="color: blue; font-weight: bold">False</span><span style="font-weight: bold">):
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>isBlue <span style="font-weight: bold">= </span>isBlue
    <span style="color: blue">self</span><span style="font-weight: bold">.</span>startGraphics<span style="font-weight: bold">(</span>state<span style="font-weight: bold">)

    </span><span style="color: green; font-style: italic"># self.drawDistributions(state)
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>distributionImages <span style="font-weight: bold">= </span><span style="color: blue">None  </span><span style="color: green; font-style: italic"># Initialized lazily
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>drawStaticObjects<span style="font-weight: bold">(</span>state<span style="font-weight: bold">)
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>drawAgentObjects<span style="font-weight: bold">(</span>state<span style="font-weight: bold">)

    </span><span style="color: green; font-style: italic"># Information
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>previousState <span style="font-weight: bold">= </span>state

  <span style="color: blue; font-weight: bold">def </span>startGraphics<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>state<span style="font-weight: bold">):
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>layout <span style="font-weight: bold">= </span>state<span style="font-weight: bold">.</span>layout
    layout <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>layout
    <span style="color: blue">self</span><span style="font-weight: bold">.</span>width <span style="font-weight: bold">= </span>layout<span style="font-weight: bold">.</span>width
    <span style="color: blue">self</span><span style="font-weight: bold">.</span>height <span style="font-weight: bold">= </span>layout<span style="font-weight: bold">.</span>height
    <span style="color: blue">self</span><span style="font-weight: bold">.</span>make_window<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>width<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>height<span style="font-weight: bold">)
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>infoPane <span style="font-weight: bold">= </span>InfoPane<span style="font-weight: bold">(</span>layout<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">)
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>currentState <span style="font-weight: bold">= </span>layout

  <span style="color: blue; font-weight: bold">def </span>drawDistributions<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>state<span style="font-weight: bold">):
    </span>walls <span style="font-weight: bold">= </span>state<span style="font-weight: bold">.</span>layout<span style="font-weight: bold">.</span>walls
    dist <span style="font-weight: bold">= []
    </span><span style="color: blue; font-weight: bold">for </span>x <span style="color: blue; font-weight: bold">in </span>range<span style="font-weight: bold">(</span>walls<span style="font-weight: bold">.</span>width<span style="font-weight: bold">):
      </span>distx <span style="font-weight: bold">= []
      </span>dist<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>distx<span style="font-weight: bold">)
      </span><span style="color: blue; font-weight: bold">for </span>y <span style="color: blue; font-weight: bold">in </span>range<span style="font-weight: bold">(</span>walls<span style="font-weight: bold">.</span>height<span style="font-weight: bold">):
          ( </span>screen_x<span style="font-weight: bold">, </span>screen_y <span style="font-weight: bold">) = </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>to_screen<span style="font-weight: bold">( (</span>x<span style="font-weight: bold">, </span>y<span style="font-weight: bold">) )
          </span>block <span style="font-weight: bold">= </span>square<span style="font-weight: bold">( (</span>screen_x<span style="font-weight: bold">, </span>screen_y<span style="font-weight: bold">),
                          </span><span style="color: red">0.5 </span><span style="font-weight: bold">* </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">,
                          </span>color <span style="font-weight: bold">= </span>BACKGROUND_COLOR<span style="font-weight: bold">,
                          </span>filled <span style="font-weight: bold">= </span><span style="color: red">1</span><span style="font-weight: bold">, </span>behind<span style="font-weight: bold">=</span><span style="color: red">2</span><span style="font-weight: bold">)
          </span>distx<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>block<span style="font-weight: bold">)
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>distributionImages <span style="font-weight: bold">= </span>dist

  <span style="color: blue; font-weight: bold">def </span>drawStaticObjects<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>state<span style="font-weight: bold">):
    </span>layout <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>layout
    <span style="color: blue">self</span><span style="font-weight: bold">.</span>drawWalls<span style="font-weight: bold">(</span>layout<span style="font-weight: bold">.</span>walls<span style="font-weight: bold">)
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>food <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>drawFood<span style="font-weight: bold">(</span>layout<span style="font-weight: bold">.</span>food<span style="font-weight: bold">)
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>capsules <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>drawCapsules<span style="font-weight: bold">(</span>layout<span style="font-weight: bold">.</span>capsules<span style="font-weight: bold">)
    </span>refresh<span style="font-weight: bold">()

  </span><span style="color: blue; font-weight: bold">def </span>drawAgentObjects<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>state<span style="font-weight: bold">):
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>agentImages <span style="font-weight: bold">= [] </span><span style="color: green; font-style: italic"># (agentState, image)
    </span><span style="color: blue; font-weight: bold">for </span>index<span style="font-weight: bold">, </span>agent <span style="color: blue; font-weight: bold">in </span>enumerate<span style="font-weight: bold">(</span>state<span style="font-weight: bold">.</span>agentStates<span style="font-weight: bold">):
      </span><span style="color: blue; font-weight: bold">if </span>agent<span style="font-weight: bold">.</span>isPacman<span style="font-weight: bold">:
        </span>image <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>drawPacman<span style="font-weight: bold">(</span>agent<span style="font-weight: bold">, </span>index<span style="font-weight: bold">)
        </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>agentImages<span style="font-weight: bold">.</span>append<span style="font-weight: bold">( (</span>agent<span style="font-weight: bold">, </span>image<span style="font-weight: bold">) )
      </span><span style="color: blue; font-weight: bold">else</span><span style="font-weight: bold">:
        </span>image <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>drawGhost<span style="font-weight: bold">(</span>agent<span style="font-weight: bold">, </span>index<span style="font-weight: bold">)
        </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>agentImages<span style="font-weight: bold">.</span>append<span style="font-weight: bold">( (</span>agent<span style="font-weight: bold">, </span>image<span style="font-weight: bold">) )
    </span>refresh<span style="font-weight: bold">()

  </span><span style="color: blue; font-weight: bold">def </span>swapImages<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>agentIndex<span style="font-weight: bold">, </span>newState<span style="font-weight: bold">):
    </span><span style="color: darkred">"""
      Changes an image from a ghost to a pacman or vis versa (for capture)
    """
    </span>prevState<span style="font-weight: bold">, </span>prevImage <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>agentImages<span style="font-weight: bold">[</span>agentIndex<span style="font-weight: bold">]
    </span><span style="color: blue; font-weight: bold">for </span>item <span style="color: blue; font-weight: bold">in </span>prevImage<span style="font-weight: bold">: </span>remove_from_screen<span style="font-weight: bold">(</span>item<span style="font-weight: bold">)
    </span><span style="color: blue; font-weight: bold">if </span>newState<span style="font-weight: bold">.</span>isPacman<span style="font-weight: bold">:
      </span>image <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>drawPacman<span style="font-weight: bold">(</span>newState<span style="font-weight: bold">, </span>agentIndex<span style="font-weight: bold">)
      </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>agentImages<span style="font-weight: bold">[</span>agentIndex<span style="font-weight: bold">] = (</span>newState<span style="font-weight: bold">, </span>image <span style="font-weight: bold">)
    </span><span style="color: blue; font-weight: bold">else</span><span style="font-weight: bold">:
      </span>image <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>drawGhost<span style="font-weight: bold">(</span>newState<span style="font-weight: bold">, </span>agentIndex<span style="font-weight: bold">)
      </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>agentImages<span style="font-weight: bold">[</span>agentIndex<span style="font-weight: bold">] = (</span>newState<span style="font-weight: bold">, </span>image <span style="font-weight: bold">)
    </span>refresh<span style="font-weight: bold">()

  </span><span style="color: blue; font-weight: bold">def </span>update<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>newState<span style="font-weight: bold">):
    </span>agentIndex <span style="font-weight: bold">= </span>newState<span style="font-weight: bold">.</span>_agentMoved
    agentState <span style="font-weight: bold">= </span>newState<span style="font-weight: bold">.</span>agentStates<span style="font-weight: bold">[</span>agentIndex<span style="font-weight: bold">]

    </span><span style="color: blue; font-weight: bold">if </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>agentImages<span style="font-weight: bold">[</span>agentIndex<span style="font-weight: bold">][</span><span style="color: red">0</span><span style="font-weight: bold">].</span>isPacman <span style="font-weight: bold">!= </span>agentState<span style="font-weight: bold">.</span>isPacman<span style="font-weight: bold">: </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>swapImages<span style="font-weight: bold">(</span>agentIndex<span style="font-weight: bold">, </span>agentState<span style="font-weight: bold">)
    </span>prevState<span style="font-weight: bold">, </span>prevImage <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>agentImages<span style="font-weight: bold">[</span>agentIndex<span style="font-weight: bold">]
    </span><span style="color: blue; font-weight: bold">if </span>agentState<span style="font-weight: bold">.</span>isPacman<span style="font-weight: bold">:
      </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>animatePacman<span style="font-weight: bold">(</span>agentState<span style="font-weight: bold">, </span>prevState<span style="font-weight: bold">, </span>prevImage<span style="font-weight: bold">)
    </span><span style="color: blue; font-weight: bold">else</span><span style="font-weight: bold">:
      </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>moveGhost<span style="font-weight: bold">(</span>agentState<span style="font-weight: bold">, </span>agentIndex<span style="font-weight: bold">, </span>prevState<span style="font-weight: bold">, </span>prevImage<span style="font-weight: bold">)
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>agentImages<span style="font-weight: bold">[</span>agentIndex<span style="font-weight: bold">] = (</span>agentState<span style="font-weight: bold">, </span>prevImage<span style="font-weight: bold">)

    </span><span style="color: blue; font-weight: bold">if </span>newState<span style="font-weight: bold">.</span>_foodEaten <span style="font-weight: bold">!= </span><span style="color: blue">None</span><span style="font-weight: bold">:
      </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>removeFood<span style="font-weight: bold">(</span>newState<span style="font-weight: bold">.</span>_foodEaten<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>food<span style="font-weight: bold">)
    </span><span style="color: blue; font-weight: bold">if </span>newState<span style="font-weight: bold">.</span>_capsuleEaten <span style="font-weight: bold">!= </span><span style="color: blue">None</span><span style="font-weight: bold">:
      </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>removeCapsule<span style="font-weight: bold">(</span>newState<span style="font-weight: bold">.</span>_capsuleEaten<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>capsules<span style="font-weight: bold">)
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>infoPane<span style="font-weight: bold">.</span>updateScore<span style="font-weight: bold">(</span>newState<span style="font-weight: bold">.</span>score<span style="font-weight: bold">)
    </span><span style="color: blue; font-weight: bold">if </span><span style="color: red">'ghostDistances' </span><span style="color: blue; font-weight: bold">in </span>dir<span style="font-weight: bold">(</span>newState<span style="font-weight: bold">):
      </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>infoPane<span style="font-weight: bold">.</span>updateGhostDistances<span style="font-weight: bold">(</span>newState<span style="font-weight: bold">.</span>ghostDistances<span style="font-weight: bold">)

  </span><span style="color: blue; font-weight: bold">def </span>make_window<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>width<span style="font-weight: bold">, </span>height<span style="font-weight: bold">):
    </span>grid_width <span style="font-weight: bold">= (</span>width<span style="font-weight: bold">-</span><span style="color: red">1</span><span style="font-weight: bold">) * </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize
    grid_height <span style="font-weight: bold">= (</span>height<span style="font-weight: bold">-</span><span style="color: red">1</span><span style="font-weight: bold">) * </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize
    screen_width <span style="font-weight: bold">= </span><span style="color: red">2</span><span style="font-weight: bold">*</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize <span style="font-weight: bold">+ </span>grid_width
    screen_height <span style="font-weight: bold">= </span><span style="color: red">2</span><span style="font-weight: bold">*</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize <span style="font-weight: bold">+ </span>grid_height <span style="font-weight: bold">+ </span>INFO_PANE_HEIGHT

    begin_graphics<span style="font-weight: bold">(</span>screen_width<span style="font-weight: bold">,
                   </span>screen_height<span style="font-weight: bold">,
                   </span>BACKGROUND_COLOR<span style="font-weight: bold">,
                   </span><span style="color: red">"CS188 Pacman"</span><span style="font-weight: bold">)

  </span><span style="color: blue; font-weight: bold">def </span>drawPacman<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>pacman<span style="font-weight: bold">, </span>index<span style="font-weight: bold">):
    </span>position <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>getPosition<span style="font-weight: bold">(</span>pacman<span style="font-weight: bold">)
    </span>screen_point <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>to_screen<span style="font-weight: bold">(</span>position<span style="font-weight: bold">)
    </span>endpoints <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>getEndpoints<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>getDirection<span style="font-weight: bold">(</span>pacman<span style="font-weight: bold">))

    </span>width <span style="font-weight: bold">= </span>PACMAN_OUTLINE_WIDTH
    outlineColor <span style="font-weight: bold">= </span>PACMAN_COLOR
    fillColor <span style="font-weight: bold">= </span>PACMAN_COLOR

    <span style="color: blue; font-weight: bold">if </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>capture<span style="font-weight: bold">:
      </span>outlineColor <span style="font-weight: bold">= </span>TEAM_COLORS<span style="font-weight: bold">[</span>index <span style="font-weight: bold">% </span><span style="color: red">2</span><span style="font-weight: bold">]
      </span>fillColor <span style="font-weight: bold">= </span>GHOST_COLORS<span style="font-weight: bold">[</span>index<span style="font-weight: bold">]
      </span>width <span style="font-weight: bold">= </span>PACMAN_CAPTURE_OUTLINE_WIDTH

    <span style="color: blue; font-weight: bold">return </span><span style="font-weight: bold">[</span>circle<span style="font-weight: bold">(</span>screen_point<span style="font-weight: bold">, </span>PACMAN_SCALE <span style="font-weight: bold">* </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">,
                   </span>fillColor <span style="font-weight: bold">= </span>fillColor<span style="font-weight: bold">, </span>outlineColor <span style="font-weight: bold">= </span>outlineColor<span style="font-weight: bold">,
                   </span>endpoints <span style="font-weight: bold">= </span>endpoints<span style="font-weight: bold">,
                   </span>width <span style="font-weight: bold">= </span>width<span style="font-weight: bold">)]

  </span><span style="color: blue; font-weight: bold">def </span>getEndpoints<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>direction<span style="font-weight: bold">, </span>position<span style="font-weight: bold">=(</span><span style="color: red">0</span><span style="font-weight: bold">,</span><span style="color: red">0</span><span style="font-weight: bold">)):
    </span>x<span style="font-weight: bold">, </span>y <span style="font-weight: bold">= </span>position
    pos <span style="font-weight: bold">= </span>x <span style="font-weight: bold">- </span>int<span style="font-weight: bold">(</span>x<span style="font-weight: bold">) + </span>y <span style="font-weight: bold">- </span>int<span style="font-weight: bold">(</span>y<span style="font-weight: bold">)
    </span>width <span style="font-weight: bold">= </span><span style="color: red">30 </span><span style="font-weight: bold">+ </span><span style="color: red">80 </span><span style="font-weight: bold">* </span>math<span style="font-weight: bold">.</span>sin<span style="font-weight: bold">(</span>math<span style="font-weight: bold">.</span>pi<span style="font-weight: bold">* </span>pos<span style="font-weight: bold">)

    </span>delta <span style="font-weight: bold">= </span>width <span style="font-weight: bold">/ </span><span style="color: red">2
    </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span>direction <span style="font-weight: bold">== </span><span style="color: red">'West'</span><span style="font-weight: bold">):
      </span>endpoints <span style="font-weight: bold">= (</span><span style="color: red">180</span><span style="font-weight: bold">+</span>delta<span style="font-weight: bold">, </span><span style="color: red">180</span><span style="font-weight: bold">-</span>delta<span style="font-weight: bold">)
    </span><span style="color: blue; font-weight: bold">elif </span><span style="font-weight: bold">(</span>direction <span style="font-weight: bold">== </span><span style="color: red">'North'</span><span style="font-weight: bold">):
      </span>endpoints <span style="font-weight: bold">= (</span><span style="color: red">90</span><span style="font-weight: bold">+</span>delta<span style="font-weight: bold">, </span><span style="color: red">90</span><span style="font-weight: bold">-</span>delta<span style="font-weight: bold">)
    </span><span style="color: blue; font-weight: bold">elif </span><span style="font-weight: bold">(</span>direction <span style="font-weight: bold">== </span><span style="color: red">'South'</span><span style="font-weight: bold">):
      </span>endpoints <span style="font-weight: bold">= (</span><span style="color: red">270</span><span style="font-weight: bold">+</span>delta<span style="font-weight: bold">, </span><span style="color: red">270</span><span style="font-weight: bold">-</span>delta<span style="font-weight: bold">)
    </span><span style="color: blue; font-weight: bold">else</span><span style="font-weight: bold">:
      </span>endpoints <span style="font-weight: bold">= (</span><span style="color: red">0</span><span style="font-weight: bold">+</span>delta<span style="font-weight: bold">, </span><span style="color: red">0</span><span style="font-weight: bold">-</span>delta<span style="font-weight: bold">)
    </span><span style="color: blue; font-weight: bold">return </span>endpoints

  <span style="color: blue; font-weight: bold">def </span>movePacman<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>position<span style="font-weight: bold">, </span>direction<span style="font-weight: bold">, </span>image<span style="font-weight: bold">):
    </span>screenPosition <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>to_screen<span style="font-weight: bold">(</span>position<span style="font-weight: bold">)
    </span>endpoints <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>getEndpoints<span style="font-weight: bold">( </span>direction<span style="font-weight: bold">, </span>position <span style="font-weight: bold">)
    </span>r <span style="font-weight: bold">= </span>PACMAN_SCALE <span style="font-weight: bold">* </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize
    moveCircle<span style="font-weight: bold">(</span>image<span style="font-weight: bold">[</span><span style="color: red">0</span><span style="font-weight: bold">], </span>screenPosition<span style="font-weight: bold">, </span>r<span style="font-weight: bold">, </span>endpoints<span style="font-weight: bold">)
    </span>refresh<span style="font-weight: bold">()

  </span><span style="color: blue; font-weight: bold">def </span>animatePacman<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>pacman<span style="font-weight: bold">, </span>prevPacman<span style="font-weight: bold">, </span>image<span style="font-weight: bold">):
    </span><span style="color: blue; font-weight: bold">if </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>frameTime <span style="font-weight: bold">&lt; </span><span style="color: red">0</span><span style="font-weight: bold">:
      </span><span style="color: blue; font-weight: bold">print </span><span style="color: red">'Press any key to step forward, "q" to play'
      </span>keys <span style="font-weight: bold">= </span>wait_for_keys<span style="font-weight: bold">()
      </span><span style="color: blue; font-weight: bold">if </span><span style="color: red">'q' </span><span style="color: blue; font-weight: bold">in </span>keys<span style="font-weight: bold">:
        </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>frameTime <span style="font-weight: bold">= </span><span style="color: red">0.1
    </span><span style="color: blue; font-weight: bold">if </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>frameTime <span style="font-weight: bold">&gt; </span><span style="color: red">0.01 </span><span style="color: blue; font-weight: bold">or </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>frameTime <span style="font-weight: bold">&lt; </span><span style="color: red">0</span><span style="font-weight: bold">:
      </span>start <span style="font-weight: bold">= </span>time<span style="font-weight: bold">.</span>time<span style="font-weight: bold">()
      </span>fx<span style="font-weight: bold">, </span>fy <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>getPosition<span style="font-weight: bold">(</span>prevPacman<span style="font-weight: bold">)
      </span>px<span style="font-weight: bold">, </span>py <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>getPosition<span style="font-weight: bold">(</span>pacman<span style="font-weight: bold">)
      </span>frames <span style="font-weight: bold">= </span><span style="color: red">4.0
      </span><span style="color: blue; font-weight: bold">for </span>i <span style="color: blue; font-weight: bold">in </span>range<span style="font-weight: bold">(</span><span style="color: red">1</span><span style="font-weight: bold">,</span>int<span style="font-weight: bold">(</span>frames<span style="font-weight: bold">) + </span><span style="color: red">1</span><span style="font-weight: bold">):
        </span>pos <span style="font-weight: bold">= </span>px<span style="font-weight: bold">*</span>i<span style="font-weight: bold">/</span>frames <span style="font-weight: bold">+ </span>fx<span style="font-weight: bold">*(</span>frames<span style="font-weight: bold">-</span>i<span style="font-weight: bold">)/</span>frames<span style="font-weight: bold">, </span>py<span style="font-weight: bold">*</span>i<span style="font-weight: bold">/</span>frames <span style="font-weight: bold">+ </span>fy<span style="font-weight: bold">*(</span>frames<span style="font-weight: bold">-</span>i<span style="font-weight: bold">)/</span>frames
        <span style="color: blue">self</span><span style="font-weight: bold">.</span>movePacman<span style="font-weight: bold">(</span>pos<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>getDirection<span style="font-weight: bold">(</span>pacman<span style="font-weight: bold">), </span>image<span style="font-weight: bold">)
        </span>refresh<span style="font-weight: bold">()
        </span>sleep<span style="font-weight: bold">(</span>abs<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>frameTime<span style="font-weight: bold">) / </span>frames<span style="font-weight: bold">)
    </span><span style="color: blue; font-weight: bold">else</span><span style="font-weight: bold">:
      </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>movePacman<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>getPosition<span style="font-weight: bold">(</span>pacman<span style="font-weight: bold">), </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>getDirection<span style="font-weight: bold">(</span>pacman<span style="font-weight: bold">), </span>image<span style="font-weight: bold">)
    </span>refresh<span style="font-weight: bold">()

  </span><span style="color: blue; font-weight: bold">def </span>getGhostColor<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>ghost<span style="font-weight: bold">, </span>ghostIndex<span style="font-weight: bold">):
    </span><span style="color: blue; font-weight: bold">if </span>ghost<span style="font-weight: bold">.</span>scaredTimer <span style="font-weight: bold">&gt; </span><span style="color: red">0</span><span style="font-weight: bold">:
      </span><span style="color: blue; font-weight: bold">return </span>SCARED_COLOR
    <span style="color: blue; font-weight: bold">else</span><span style="font-weight: bold">:
      </span><span style="color: blue; font-weight: bold">return </span>GHOST_COLORS<span style="font-weight: bold">[</span>ghostIndex<span style="font-weight: bold">]

  </span><span style="color: blue; font-weight: bold">def </span>drawGhost<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>ghost<span style="font-weight: bold">, </span>agentIndex<span style="font-weight: bold">):
    </span>pos <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>getPosition<span style="font-weight: bold">(</span>ghost<span style="font-weight: bold">)
    </span>dir <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>getDirection<span style="font-weight: bold">(</span>ghost<span style="font-weight: bold">)
    (</span>screen_x<span style="font-weight: bold">, </span>screen_y<span style="font-weight: bold">) = (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>to_screen<span style="font-weight: bold">(</span>pos<span style="font-weight: bold">) )
    </span>coords <span style="font-weight: bold">= []
    </span><span style="color: blue; font-weight: bold">for </span><span style="font-weight: bold">(</span>x<span style="font-weight: bold">, </span>y<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">in </span>GHOST_SHAPE<span style="font-weight: bold">:
      </span>coords<span style="font-weight: bold">.</span>append<span style="font-weight: bold">((</span>x<span style="font-weight: bold">*</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE <span style="font-weight: bold">+ </span>screen_x<span style="font-weight: bold">, </span>y<span style="font-weight: bold">*</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE <span style="font-weight: bold">+ </span>screen_y<span style="font-weight: bold">))

    </span>colour <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>getGhostColor<span style="font-weight: bold">(</span>ghost<span style="font-weight: bold">, </span>agentIndex<span style="font-weight: bold">)
    </span>body <span style="font-weight: bold">= </span>polygon<span style="font-weight: bold">(</span>coords<span style="font-weight: bold">, </span>colour<span style="font-weight: bold">, </span>filled <span style="font-weight: bold">= </span><span style="color: red">1</span><span style="font-weight: bold">)
    </span>WHITE <span style="font-weight: bold">= </span>formatColor<span style="font-weight: bold">(</span><span style="color: red">1.0</span><span style="font-weight: bold">, </span><span style="color: red">1.0</span><span style="font-weight: bold">, </span><span style="color: red">1.0</span><span style="font-weight: bold">)
    </span>BLACK <span style="font-weight: bold">= </span>formatColor<span style="font-weight: bold">(</span><span style="color: red">0.0</span><span style="font-weight: bold">, </span><span style="color: red">0.0</span><span style="font-weight: bold">, </span><span style="color: red">0.0</span><span style="font-weight: bold">)

    </span>dx <span style="font-weight: bold">= </span><span style="color: red">0
    </span>dy <span style="font-weight: bold">= </span><span style="color: red">0
    </span><span style="color: blue; font-weight: bold">if </span>dir <span style="font-weight: bold">== </span><span style="color: red">'North'</span><span style="font-weight: bold">:
      </span>dy <span style="font-weight: bold">= -</span><span style="color: red">0.2
    </span><span style="color: blue; font-weight: bold">if </span>dir <span style="font-weight: bold">== </span><span style="color: red">'South'</span><span style="font-weight: bold">:
      </span>dy <span style="font-weight: bold">= </span><span style="color: red">0.2
    </span><span style="color: blue; font-weight: bold">if </span>dir <span style="font-weight: bold">== </span><span style="color: red">'East'</span><span style="font-weight: bold">:
      </span>dx <span style="font-weight: bold">= </span><span style="color: red">0.2
    </span><span style="color: blue; font-weight: bold">if </span>dir <span style="font-weight: bold">== </span><span style="color: red">'West'</span><span style="font-weight: bold">:
      </span>dx <span style="font-weight: bold">= -</span><span style="color: red">0.2
    </span>leftEye <span style="font-weight: bold">= </span>circle<span style="font-weight: bold">((</span>screen_x<span style="font-weight: bold">+</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*(-</span><span style="color: red">0.3</span><span style="font-weight: bold">+</span>dx<span style="font-weight: bold">/</span><span style="color: red">1.5</span><span style="font-weight: bold">), </span>screen_y<span style="font-weight: bold">-</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*(</span><span style="color: red">0.3</span><span style="font-weight: bold">-</span>dy<span style="font-weight: bold">/</span><span style="color: red">1.5</span><span style="font-weight: bold">)), </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*</span><span style="color: red">0.2</span><span style="font-weight: bold">, </span>WHITE<span style="font-weight: bold">, </span>WHITE<span style="font-weight: bold">)
    </span>rightEye <span style="font-weight: bold">= </span>circle<span style="font-weight: bold">((</span>screen_x<span style="font-weight: bold">+</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*(</span><span style="color: red">0.3</span><span style="font-weight: bold">+</span>dx<span style="font-weight: bold">/</span><span style="color: red">1.5</span><span style="font-weight: bold">), </span>screen_y<span style="font-weight: bold">-</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*(</span><span style="color: red">0.3</span><span style="font-weight: bold">-</span>dy<span style="font-weight: bold">/</span><span style="color: red">1.5</span><span style="font-weight: bold">)), </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*</span><span style="color: red">0.2</span><span style="font-weight: bold">, </span>WHITE<span style="font-weight: bold">, </span>WHITE<span style="font-weight: bold">)
    </span>leftPupil <span style="font-weight: bold">= </span>circle<span style="font-weight: bold">((</span>screen_x<span style="font-weight: bold">+</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*(-</span><span style="color: red">0.3</span><span style="font-weight: bold">+</span>dx<span style="font-weight: bold">), </span>screen_y<span style="font-weight: bold">-</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*(</span><span style="color: red">0.3</span><span style="font-weight: bold">-</span>dy<span style="font-weight: bold">)), </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*</span><span style="color: red">0.08</span><span style="font-weight: bold">, </span>BLACK<span style="font-weight: bold">, </span>BLACK<span style="font-weight: bold">)
    </span>rightPupil <span style="font-weight: bold">= </span>circle<span style="font-weight: bold">((</span>screen_x<span style="font-weight: bold">+</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*(</span><span style="color: red">0.3</span><span style="font-weight: bold">+</span>dx<span style="font-weight: bold">), </span>screen_y<span style="font-weight: bold">-</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*(</span><span style="color: red">0.3</span><span style="font-weight: bold">-</span>dy<span style="font-weight: bold">)), </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*</span><span style="color: red">0.08</span><span style="font-weight: bold">, </span>BLACK<span style="font-weight: bold">, </span>BLACK<span style="font-weight: bold">)
    </span>ghostImageParts <span style="font-weight: bold">= []
    </span>ghostImageParts<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>body<span style="font-weight: bold">)
    </span>ghostImageParts<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>leftEye<span style="font-weight: bold">)
    </span>ghostImageParts<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>rightEye<span style="font-weight: bold">)
    </span>ghostImageParts<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>leftPupil<span style="font-weight: bold">)
    </span>ghostImageParts<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>rightPupil<span style="font-weight: bold">)

    </span><span style="color: blue; font-weight: bold">return </span>ghostImageParts

  <span style="color: blue; font-weight: bold">def </span>moveEyes<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>pos<span style="font-weight: bold">, </span>dir<span style="font-weight: bold">, </span>eyes<span style="font-weight: bold">):
    (</span>screen_x<span style="font-weight: bold">, </span>screen_y<span style="font-weight: bold">) = (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>to_screen<span style="font-weight: bold">(</span>pos<span style="font-weight: bold">) )
    </span>dx <span style="font-weight: bold">= </span><span style="color: red">0
    </span>dy <span style="font-weight: bold">= </span><span style="color: red">0
    </span><span style="color: blue; font-weight: bold">if </span>dir <span style="font-weight: bold">== </span><span style="color: red">'North'</span><span style="font-weight: bold">:
      </span>dy <span style="font-weight: bold">= -</span><span style="color: red">0.2
    </span><span style="color: blue; font-weight: bold">if </span>dir <span style="font-weight: bold">== </span><span style="color: red">'South'</span><span style="font-weight: bold">:
      </span>dy <span style="font-weight: bold">= </span><span style="color: red">0.2
    </span><span style="color: blue; font-weight: bold">if </span>dir <span style="font-weight: bold">== </span><span style="color: red">'East'</span><span style="font-weight: bold">:
      </span>dx <span style="font-weight: bold">= </span><span style="color: red">0.2
    </span><span style="color: blue; font-weight: bold">if </span>dir <span style="font-weight: bold">== </span><span style="color: red">'West'</span><span style="font-weight: bold">:
      </span>dx <span style="font-weight: bold">= -</span><span style="color: red">0.2
    </span>moveCircle<span style="font-weight: bold">(</span>eyes<span style="font-weight: bold">[</span><span style="color: red">0</span><span style="font-weight: bold">],(</span>screen_x<span style="font-weight: bold">+</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*(-</span><span style="color: red">0.3</span><span style="font-weight: bold">+</span>dx<span style="font-weight: bold">/</span><span style="color: red">1.5</span><span style="font-weight: bold">), </span>screen_y<span style="font-weight: bold">-</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*(</span><span style="color: red">0.3</span><span style="font-weight: bold">-</span>dy<span style="font-weight: bold">/</span><span style="color: red">1.5</span><span style="font-weight: bold">)), </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*</span><span style="color: red">0.2</span><span style="font-weight: bold">)
    </span>moveCircle<span style="font-weight: bold">(</span>eyes<span style="font-weight: bold">[</span><span style="color: red">1</span><span style="font-weight: bold">],(</span>screen_x<span style="font-weight: bold">+</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*(</span><span style="color: red">0.3</span><span style="font-weight: bold">+</span>dx<span style="font-weight: bold">/</span><span style="color: red">1.5</span><span style="font-weight: bold">), </span>screen_y<span style="font-weight: bold">-</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*(</span><span style="color: red">0.3</span><span style="font-weight: bold">-</span>dy<span style="font-weight: bold">/</span><span style="color: red">1.5</span><span style="font-weight: bold">)), </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*</span><span style="color: red">0.2</span><span style="font-weight: bold">)
    </span>moveCircle<span style="font-weight: bold">(</span>eyes<span style="font-weight: bold">[</span><span style="color: red">2</span><span style="font-weight: bold">],(</span>screen_x<span style="font-weight: bold">+</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*(-</span><span style="color: red">0.3</span><span style="font-weight: bold">+</span>dx<span style="font-weight: bold">), </span>screen_y<span style="font-weight: bold">-</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*(</span><span style="color: red">0.3</span><span style="font-weight: bold">-</span>dy<span style="font-weight: bold">)), </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*</span><span style="color: red">0.08</span><span style="font-weight: bold">)
    </span>moveCircle<span style="font-weight: bold">(</span>eyes<span style="font-weight: bold">[</span><span style="color: red">3</span><span style="font-weight: bold">],(</span>screen_x<span style="font-weight: bold">+</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*(</span><span style="color: red">0.3</span><span style="font-weight: bold">+</span>dx<span style="font-weight: bold">), </span>screen_y<span style="font-weight: bold">-</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*(</span><span style="color: red">0.3</span><span style="font-weight: bold">-</span>dy<span style="font-weight: bold">)), </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>GHOST_SIZE<span style="font-weight: bold">*</span><span style="color: red">0.08</span><span style="font-weight: bold">)

  </span><span style="color: blue; font-weight: bold">def </span>moveGhost<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>ghost<span style="font-weight: bold">, </span>ghostIndex<span style="font-weight: bold">, </span>prevGhost<span style="font-weight: bold">, </span>ghostImageParts<span style="font-weight: bold">):
    </span>old_x<span style="font-weight: bold">, </span>old_y <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>to_screen<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>getPosition<span style="font-weight: bold">(</span>prevGhost<span style="font-weight: bold">))
    </span>new_x<span style="font-weight: bold">, </span>new_y <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>to_screen<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>getPosition<span style="font-weight: bold">(</span>ghost<span style="font-weight: bold">))
    </span>delta <span style="font-weight: bold">= </span>new_x <span style="font-weight: bold">- </span>old_x<span style="font-weight: bold">, </span>new_y <span style="font-weight: bold">- </span>old_y

    <span style="color: blue; font-weight: bold">for </span>ghostImagePart <span style="color: blue; font-weight: bold">in </span>ghostImageParts<span style="font-weight: bold">:
      </span>move_by<span style="font-weight: bold">(</span>ghostImagePart<span style="font-weight: bold">, </span>delta<span style="font-weight: bold">)
    </span>refresh<span style="font-weight: bold">()

    </span><span style="color: blue; font-weight: bold">if </span>ghost<span style="font-weight: bold">.</span>scaredTimer <span style="font-weight: bold">&gt; </span><span style="color: red">0</span><span style="font-weight: bold">:
      </span>color <span style="font-weight: bold">= </span>SCARED_COLOR
    <span style="color: blue; font-weight: bold">else</span><span style="font-weight: bold">:
      </span>color <span style="font-weight: bold">= </span>GHOST_COLORS<span style="font-weight: bold">[</span>ghostIndex<span style="font-weight: bold">]
    </span>edit<span style="font-weight: bold">(</span>ghostImageParts<span style="font-weight: bold">[</span><span style="color: red">0</span><span style="font-weight: bold">], (</span><span style="color: red">'fill'</span><span style="font-weight: bold">, </span>color<span style="font-weight: bold">), (</span><span style="color: red">'outline'</span><span style="font-weight: bold">, </span>color<span style="font-weight: bold">))
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>moveEyes<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>getPosition<span style="font-weight: bold">(</span>ghost<span style="font-weight: bold">), </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>getDirection<span style="font-weight: bold">(</span>ghost<span style="font-weight: bold">), </span>ghostImageParts<span style="font-weight: bold">[-</span><span style="color: red">4</span><span style="font-weight: bold">:])
    </span>refresh<span style="font-weight: bold">()

  </span><span style="color: blue; font-weight: bold">def </span>getPosition<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>agentState<span style="font-weight: bold">):
    </span><span style="color: blue; font-weight: bold">if </span>agentState<span style="font-weight: bold">.</span>configuration <span style="font-weight: bold">== </span><span style="color: blue">None</span><span style="font-weight: bold">: </span><span style="color: blue; font-weight: bold">return </span><span style="font-weight: bold">(-</span><span style="color: red">1000</span><span style="font-weight: bold">, -</span><span style="color: red">1000</span><span style="font-weight: bold">)
    </span><span style="color: blue; font-weight: bold">return </span>agentState<span style="font-weight: bold">.</span>getPosition<span style="font-weight: bold">()

  </span><span style="color: blue; font-weight: bold">def </span>getDirection<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>agentState<span style="font-weight: bold">):
    </span><span style="color: blue; font-weight: bold">if </span>agentState<span style="font-weight: bold">.</span>configuration <span style="font-weight: bold">== </span><span style="color: blue">None</span><span style="font-weight: bold">: </span><span style="color: blue; font-weight: bold">return </span>Directions<span style="font-weight: bold">.</span>STOP
    <span style="color: blue; font-weight: bold">return </span>agentState<span style="font-weight: bold">.</span>configuration<span style="font-weight: bold">.</span>getDirection<span style="font-weight: bold">()

  </span><span style="color: blue; font-weight: bold">def </span>finish<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">):
    </span>end_graphics<span style="font-weight: bold">()

  </span><span style="color: blue; font-weight: bold">def </span>to_screen<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>point<span style="font-weight: bold">):
    ( </span>x<span style="font-weight: bold">, </span>y <span style="font-weight: bold">) = </span>point
    <span style="color: green; font-style: italic">#y = self.height - y
    </span>x <span style="font-weight: bold">= (</span>x <span style="font-weight: bold">+ </span><span style="color: red">1</span><span style="font-weight: bold">)*</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize
    y <span style="font-weight: bold">= (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>height  <span style="font-weight: bold">- </span>y<span style="font-weight: bold">)*</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize
    <span style="color: blue; font-weight: bold">return </span><span style="font-weight: bold">( </span>x<span style="font-weight: bold">, </span>y <span style="font-weight: bold">)

  </span><span style="color: green; font-style: italic"># Fixes some TK issue with off-center circles
  </span><span style="color: blue; font-weight: bold">def </span>to_screen2<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>point<span style="font-weight: bold">):
    ( </span>x<span style="font-weight: bold">, </span>y <span style="font-weight: bold">) = </span>point
    <span style="color: green; font-style: italic">#y = self.height - y
    </span>x <span style="font-weight: bold">= (</span>x <span style="font-weight: bold">+ </span><span style="color: red">1</span><span style="font-weight: bold">)*</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize
    y <span style="font-weight: bold">= (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>height  <span style="font-weight: bold">- </span>y<span style="font-weight: bold">)*</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize
    <span style="color: blue; font-weight: bold">return </span><span style="font-weight: bold">( </span>x<span style="font-weight: bold">, </span>y <span style="font-weight: bold">)

  </span><span style="color: blue; font-weight: bold">def </span>drawWalls<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>wallMatrix<span style="font-weight: bold">):
    </span>wallColor <span style="font-weight: bold">= </span>WALL_COLOR
    <span style="color: blue; font-weight: bold">for </span>xNum<span style="font-weight: bold">, </span>x <span style="color: blue; font-weight: bold">in </span>enumerate<span style="font-weight: bold">(</span>wallMatrix<span style="font-weight: bold">):
      </span><span style="color: blue; font-weight: bold">if </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>capture <span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span>xNum <span style="font-weight: bold">* </span><span style="color: red">2</span><span style="font-weight: bold">) &lt; </span>wallMatrix<span style="font-weight: bold">.</span>width<span style="font-weight: bold">: </span>wallColor <span style="font-weight: bold">= </span>TEAM_COLORS<span style="font-weight: bold">[</span><span style="color: red">0</span><span style="font-weight: bold">]
      </span><span style="color: blue; font-weight: bold">if </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>capture <span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span>xNum <span style="font-weight: bold">* </span><span style="color: red">2</span><span style="font-weight: bold">) &gt;= </span>wallMatrix<span style="font-weight: bold">.</span>width<span style="font-weight: bold">: </span>wallColor <span style="font-weight: bold">= </span>TEAM_COLORS<span style="font-weight: bold">[</span><span style="color: red">1</span><span style="font-weight: bold">]

      </span><span style="color: blue; font-weight: bold">for </span>yNum<span style="font-weight: bold">, </span>cell <span style="color: blue; font-weight: bold">in </span>enumerate<span style="font-weight: bold">(</span>x<span style="font-weight: bold">):
        </span><span style="color: blue; font-weight: bold">if </span>cell<span style="font-weight: bold">: </span><span style="color: green; font-style: italic"># There's a wall here
          </span>pos <span style="font-weight: bold">= (</span>xNum<span style="font-weight: bold">, </span>yNum<span style="font-weight: bold">)
          </span>screen <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>to_screen<span style="font-weight: bold">(</span>pos<span style="font-weight: bold">)
          </span>screen2 <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>to_screen2<span style="font-weight: bold">(</span>pos<span style="font-weight: bold">)

          </span><span style="color: green; font-style: italic"># draw each quadrant of the square based on adjacent walls
          </span>wIsWall <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>isWall<span style="font-weight: bold">(</span>xNum<span style="font-weight: bold">-</span><span style="color: red">1</span><span style="font-weight: bold">, </span>yNum<span style="font-weight: bold">, </span>wallMatrix<span style="font-weight: bold">)
          </span>eIsWall <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>isWall<span style="font-weight: bold">(</span>xNum<span style="font-weight: bold">+</span><span style="color: red">1</span><span style="font-weight: bold">, </span>yNum<span style="font-weight: bold">, </span>wallMatrix<span style="font-weight: bold">)
          </span>nIsWall <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>isWall<span style="font-weight: bold">(</span>xNum<span style="font-weight: bold">, </span>yNum<span style="font-weight: bold">+</span><span style="color: red">1</span><span style="font-weight: bold">, </span>wallMatrix<span style="font-weight: bold">)
          </span>sIsWall <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>isWall<span style="font-weight: bold">(</span>xNum<span style="font-weight: bold">, </span>yNum<span style="font-weight: bold">-</span><span style="color: red">1</span><span style="font-weight: bold">, </span>wallMatrix<span style="font-weight: bold">)
          </span>nwIsWall <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>isWall<span style="font-weight: bold">(</span>xNum<span style="font-weight: bold">-</span><span style="color: red">1</span><span style="font-weight: bold">, </span>yNum<span style="font-weight: bold">+</span><span style="color: red">1</span><span style="font-weight: bold">, </span>wallMatrix<span style="font-weight: bold">)
          </span>swIsWall <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>isWall<span style="font-weight: bold">(</span>xNum<span style="font-weight: bold">-</span><span style="color: red">1</span><span style="font-weight: bold">, </span>yNum<span style="font-weight: bold">-</span><span style="color: red">1</span><span style="font-weight: bold">, </span>wallMatrix<span style="font-weight: bold">)
          </span>neIsWall <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>isWall<span style="font-weight: bold">(</span>xNum<span style="font-weight: bold">+</span><span style="color: red">1</span><span style="font-weight: bold">, </span>yNum<span style="font-weight: bold">+</span><span style="color: red">1</span><span style="font-weight: bold">, </span>wallMatrix<span style="font-weight: bold">)
          </span>seIsWall <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>isWall<span style="font-weight: bold">(</span>xNum<span style="font-weight: bold">+</span><span style="color: red">1</span><span style="font-weight: bold">, </span>yNum<span style="font-weight: bold">-</span><span style="color: red">1</span><span style="font-weight: bold">, </span>wallMatrix<span style="font-weight: bold">)

          </span><span style="color: green; font-style: italic"># NE quadrant
          </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>nIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>eIsWall<span style="font-weight: bold">):
            </span><span style="color: green; font-style: italic"># inner circle
            </span>circle<span style="font-weight: bold">(</span>screen2<span style="font-weight: bold">, </span>WALL_RADIUS <span style="font-weight: bold">* </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">, </span>wallColor<span style="font-weight: bold">, </span>wallColor<span style="font-weight: bold">, (</span><span style="color: red">0</span><span style="font-weight: bold">,</span><span style="color: red">91</span><span style="font-weight: bold">), </span><span style="color: red">'arc'</span><span style="font-weight: bold">)
          </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span>nIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>eIsWall<span style="font-weight: bold">):
            </span><span style="color: green; font-style: italic"># vertical line
            </span>line<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: red">0</span><span style="font-weight: bold">)), </span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">0.5</span><span style="font-weight: bold">)-</span><span style="color: red">1</span><span style="font-weight: bold">)), </span>wallColor<span style="font-weight: bold">)
          </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>nIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span>eIsWall<span style="font-weight: bold">):
            </span><span style="color: green; font-style: italic"># horizontal line
            </span>line<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: red">0</span><span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span><span style="color: red">0.5</span><span style="font-weight: bold">+</span><span style="color: red">1</span><span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>wallColor<span style="font-weight: bold">)
          </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span>nIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span>eIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>neIsWall<span style="font-weight: bold">):
            </span><span style="color: green; font-style: italic"># outer circle
            </span>circle<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen2<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span><span style="color: red">2</span><span style="font-weight: bold">*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">2</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>WALL_RADIUS <span style="font-weight: bold">* </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">-</span><span style="color: red">1</span><span style="font-weight: bold">, </span>wallColor<span style="font-weight: bold">, </span>wallColor<span style="font-weight: bold">, (</span><span style="color: red">180</span><span style="font-weight: bold">,</span><span style="color: red">271</span><span style="font-weight: bold">), </span><span style="color: red">'arc'</span><span style="font-weight: bold">)
            </span>line<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span><span style="color: red">2</span><span style="font-weight: bold">*</span>WALL_RADIUS<span style="font-weight: bold">-</span><span style="color: red">1</span><span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span><span style="color: red">0.5</span><span style="font-weight: bold">+</span><span style="color: red">1</span><span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>wallColor<span style="font-weight: bold">)
            </span>line<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">2</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">+</span><span style="color: red">1</span><span style="font-weight: bold">)), </span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">0.5</span><span style="font-weight: bold">))), </span>wallColor<span style="font-weight: bold">)

          </span><span style="color: green; font-style: italic"># NW quadrant
          </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>nIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>wIsWall<span style="font-weight: bold">):
            </span><span style="color: green; font-style: italic"># inner circle
            </span>circle<span style="font-weight: bold">(</span>screen2<span style="font-weight: bold">, </span>WALL_RADIUS <span style="font-weight: bold">* </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">, </span>wallColor<span style="font-weight: bold">, </span>wallColor<span style="font-weight: bold">, (</span><span style="color: red">90</span><span style="font-weight: bold">,</span><span style="color: red">181</span><span style="font-weight: bold">), </span><span style="color: red">'arc'</span><span style="font-weight: bold">)
          </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span>nIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>wIsWall<span style="font-weight: bold">):
            </span><span style="color: green; font-style: italic"># vertical line
            </span>line<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: red">0</span><span style="font-weight: bold">)), </span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">0.5</span><span style="font-weight: bold">)-</span><span style="color: red">1</span><span style="font-weight: bold">)), </span>wallColor<span style="font-weight: bold">)
          </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>nIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span>wIsWall<span style="font-weight: bold">):
            </span><span style="color: green; font-style: italic"># horizontal line
            </span>line<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: red">0</span><span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">0.5</span><span style="font-weight: bold">)-</span><span style="color: red">1</span><span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>wallColor<span style="font-weight: bold">)
          </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span>nIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span>wIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>nwIsWall<span style="font-weight: bold">):
            </span><span style="color: green; font-style: italic"># outer circle
            </span>circle<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen2<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">2</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">2</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>WALL_RADIUS <span style="font-weight: bold">* </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">-</span><span style="color: red">1</span><span style="font-weight: bold">, </span>wallColor<span style="font-weight: bold">, </span>wallColor<span style="font-weight: bold">, (</span><span style="color: red">270</span><span style="font-weight: bold">,</span><span style="color: red">361</span><span style="font-weight: bold">), </span><span style="color: red">'arc'</span><span style="font-weight: bold">)
            </span>line<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">2</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">+</span><span style="color: red">1</span><span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">0.5</span><span style="font-weight: bold">), </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>wallColor<span style="font-weight: bold">)
            </span>line<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">2</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">+</span><span style="color: red">1</span><span style="font-weight: bold">)), </span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">0.5</span><span style="font-weight: bold">))), </span>wallColor<span style="font-weight: bold">)

          </span><span style="color: green; font-style: italic"># SE quadrant
          </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>sIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>eIsWall<span style="font-weight: bold">):
            </span><span style="color: green; font-style: italic"># inner circle
            </span>circle<span style="font-weight: bold">(</span>screen2<span style="font-weight: bold">, </span>WALL_RADIUS <span style="font-weight: bold">* </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">, </span>wallColor<span style="font-weight: bold">, </span>wallColor<span style="font-weight: bold">, (</span><span style="color: red">270</span><span style="font-weight: bold">,</span><span style="color: red">361</span><span style="font-weight: bold">), </span><span style="color: red">'arc'</span><span style="font-weight: bold">)
          </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span>sIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>eIsWall<span style="font-weight: bold">):
            </span><span style="color: green; font-style: italic"># vertical line
            </span>line<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: red">0</span><span style="font-weight: bold">)), </span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(</span><span style="color: red">0.5</span><span style="font-weight: bold">)+</span><span style="color: red">1</span><span style="font-weight: bold">)), </span>wallColor<span style="font-weight: bold">)
          </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>sIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span>eIsWall<span style="font-weight: bold">):
            </span><span style="color: green; font-style: italic"># horizontal line
            </span>line<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: red">0</span><span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span><span style="color: red">0.5</span><span style="font-weight: bold">+</span><span style="color: red">1</span><span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>wallColor<span style="font-weight: bold">)
          </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span>sIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span>eIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>seIsWall<span style="font-weight: bold">):
            </span><span style="color: green; font-style: italic"># outer circle
            </span>circle<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen2<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span><span style="color: red">2</span><span style="font-weight: bold">*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(</span><span style="color: red">2</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>WALL_RADIUS <span style="font-weight: bold">* </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">-</span><span style="color: red">1</span><span style="font-weight: bold">, </span>wallColor<span style="font-weight: bold">, </span>wallColor<span style="font-weight: bold">, (</span><span style="color: red">90</span><span style="font-weight: bold">,</span><span style="color: red">181</span><span style="font-weight: bold">), </span><span style="color: red">'arc'</span><span style="font-weight: bold">)
            </span>line<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span><span style="color: red">2</span><span style="font-weight: bold">*</span>WALL_RADIUS<span style="font-weight: bold">-</span><span style="color: red">1</span><span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span><span style="color: red">0.5</span><span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>wallColor<span style="font-weight: bold">)
            </span>line<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(</span><span style="color: red">2</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">-</span><span style="color: red">1</span><span style="font-weight: bold">)), </span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(</span><span style="color: red">0.5</span><span style="font-weight: bold">))), </span>wallColor<span style="font-weight: bold">)

          </span><span style="color: green; font-style: italic"># SW quadrant
          </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>sIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>wIsWall<span style="font-weight: bold">):
            </span><span style="color: green; font-style: italic"># inner circle
            </span>circle<span style="font-weight: bold">(</span>screen2<span style="font-weight: bold">, </span>WALL_RADIUS <span style="font-weight: bold">* </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">, </span>wallColor<span style="font-weight: bold">, </span>wallColor<span style="font-weight: bold">, (</span><span style="color: red">180</span><span style="font-weight: bold">,</span><span style="color: red">271</span><span style="font-weight: bold">), </span><span style="color: red">'arc'</span><span style="font-weight: bold">)
          </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span>sIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>wIsWall<span style="font-weight: bold">):
            </span><span style="color: green; font-style: italic"># vertical line
            </span>line<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: red">0</span><span style="font-weight: bold">)), </span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(</span><span style="color: red">0.5</span><span style="font-weight: bold">)+</span><span style="color: red">1</span><span style="font-weight: bold">)), </span>wallColor<span style="font-weight: bold">)
          </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>sIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span>wIsWall<span style="font-weight: bold">):
            </span><span style="color: green; font-style: italic"># horizontal line
            </span>line<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: red">0</span><span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">0.5</span><span style="font-weight: bold">)-</span><span style="color: red">1</span><span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>wallColor<span style="font-weight: bold">)
          </span><span style="color: blue; font-weight: bold">if </span><span style="font-weight: bold">(</span>sIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span>wIsWall<span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span><span style="color: blue; font-weight: bold">not </span>swIsWall<span style="font-weight: bold">):
            </span><span style="color: green; font-style: italic"># outer circle
            </span>circle<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen2<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">2</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(</span><span style="color: red">2</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>WALL_RADIUS <span style="font-weight: bold">* </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">-</span><span style="color: red">1</span><span style="font-weight: bold">, </span>wallColor<span style="font-weight: bold">, </span>wallColor<span style="font-weight: bold">, (</span><span style="color: red">0</span><span style="font-weight: bold">,</span><span style="color: red">91</span><span style="font-weight: bold">), </span><span style="color: red">'arc'</span><span style="font-weight: bold">)
            </span>line<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">2</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">+</span><span style="color: red">1</span><span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">0.5</span><span style="font-weight: bold">), </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">)), </span>wallColor<span style="font-weight: bold">)
            </span>line<span style="font-weight: bold">(</span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(</span><span style="color: red">2</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">-</span><span style="color: red">1</span><span style="font-weight: bold">)), </span>add<span style="font-weight: bold">(</span>screen<span style="font-weight: bold">, (</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(-</span><span style="color: red">1</span><span style="font-weight: bold">)*</span>WALL_RADIUS<span style="font-weight: bold">, </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">*(</span><span style="color: red">0.5</span><span style="font-weight: bold">))), </span>wallColor<span style="font-weight: bold">)

  </span><span style="color: blue; font-weight: bold">def </span>isWall<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>x<span style="font-weight: bold">, </span>y<span style="font-weight: bold">, </span>walls<span style="font-weight: bold">):
    </span><span style="color: blue; font-weight: bold">if </span>x <span style="font-weight: bold">&lt; </span><span style="color: red">0 </span><span style="color: blue; font-weight: bold">or </span>y <span style="font-weight: bold">&lt; </span><span style="color: red">0</span><span style="font-weight: bold">:
      </span><span style="color: blue; font-weight: bold">return False
    if </span>x <span style="font-weight: bold">&gt;= </span>walls<span style="font-weight: bold">.</span>width <span style="color: blue; font-weight: bold">or </span>y <span style="font-weight: bold">&gt;= </span>walls<span style="font-weight: bold">.</span>height<span style="font-weight: bold">:
      </span><span style="color: blue; font-weight: bold">return False
    return </span>walls<span style="font-weight: bold">[</span>x<span style="font-weight: bold">][</span>y<span style="font-weight: bold">]

  </span><span style="color: blue; font-weight: bold">def </span>drawFood<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>foodMatrix <span style="font-weight: bold">):
    </span>foodImages <span style="font-weight: bold">= []
    </span>color <span style="font-weight: bold">= </span>FOOD_COLOR
    <span style="color: blue; font-weight: bold">for </span>xNum<span style="font-weight: bold">, </span>x <span style="color: blue; font-weight: bold">in </span>enumerate<span style="font-weight: bold">(</span>foodMatrix<span style="font-weight: bold">):
      </span><span style="color: blue; font-weight: bold">if </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>capture <span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span>xNum <span style="font-weight: bold">* </span><span style="color: red">2</span><span style="font-weight: bold">) &lt;= </span>foodMatrix<span style="font-weight: bold">.</span>width<span style="font-weight: bold">: </span>color <span style="font-weight: bold">= </span>TEAM_COLORS<span style="font-weight: bold">[</span><span style="color: red">0</span><span style="font-weight: bold">]
      </span><span style="color: blue; font-weight: bold">if </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>capture <span style="color: blue; font-weight: bold">and </span><span style="font-weight: bold">(</span>xNum <span style="font-weight: bold">* </span><span style="color: red">2</span><span style="font-weight: bold">) &gt; </span>foodMatrix<span style="font-weight: bold">.</span>width<span style="font-weight: bold">: </span>color <span style="font-weight: bold">= </span>TEAM_COLORS<span style="font-weight: bold">[</span><span style="color: red">1</span><span style="font-weight: bold">]
      </span>imageRow <span style="font-weight: bold">= []
      </span>foodImages<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>imageRow<span style="font-weight: bold">)
      </span><span style="color: blue; font-weight: bold">for </span>yNum<span style="font-weight: bold">, </span>cell <span style="color: blue; font-weight: bold">in </span>enumerate<span style="font-weight: bold">(</span>x<span style="font-weight: bold">):
        </span><span style="color: blue; font-weight: bold">if </span>cell<span style="font-weight: bold">: </span><span style="color: green; font-style: italic"># There's food here
          </span>screen <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>to_screen<span style="font-weight: bold">((</span>xNum<span style="font-weight: bold">, </span>yNum <span style="font-weight: bold">))
          </span>dot <span style="font-weight: bold">= </span>circle<span style="font-weight: bold">( </span>screen<span style="font-weight: bold">,
                        </span>FOOD_SIZE <span style="font-weight: bold">* </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">,
                        </span>outlineColor <span style="font-weight: bold">= </span>color<span style="font-weight: bold">, </span>fillColor <span style="font-weight: bold">= </span>color<span style="font-weight: bold">,
                        </span>width <span style="font-weight: bold">= </span><span style="color: red">1</span><span style="font-weight: bold">)
          </span>imageRow<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>dot<span style="font-weight: bold">)
        </span><span style="color: blue; font-weight: bold">else</span><span style="font-weight: bold">:
          </span>imageRow<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span><span style="color: blue">None</span><span style="font-weight: bold">)
    </span><span style="color: blue; font-weight: bold">return </span>foodImages

  <span style="color: blue; font-weight: bold">def </span>drawCapsules<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>capsules <span style="font-weight: bold">):
    </span>capsuleImages <span style="font-weight: bold">= {}
    </span><span style="color: blue; font-weight: bold">for </span>capsule <span style="color: blue; font-weight: bold">in </span>capsules<span style="font-weight: bold">:
      ( </span>screen_x<span style="font-weight: bold">, </span>screen_y <span style="font-weight: bold">) = </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>to_screen<span style="font-weight: bold">(</span>capsule<span style="font-weight: bold">)
      </span>dot <span style="font-weight: bold">= </span>circle<span style="font-weight: bold">( (</span>screen_x<span style="font-weight: bold">, </span>screen_y<span style="font-weight: bold">),
                        </span>CAPSULE_SIZE <span style="font-weight: bold">* </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">,
                        </span>outlineColor <span style="font-weight: bold">= </span>CAPSULE_COLOR<span style="font-weight: bold">,
                        </span>fillColor <span style="font-weight: bold">= </span>CAPSULE_COLOR<span style="font-weight: bold">,
                        </span>width <span style="font-weight: bold">= </span><span style="color: red">1</span><span style="font-weight: bold">)
      </span>capsuleImages<span style="font-weight: bold">[</span>capsule<span style="font-weight: bold">] = </span>dot
    <span style="color: blue; font-weight: bold">return </span>capsuleImages

  <span style="color: blue; font-weight: bold">def </span>removeFood<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>cell<span style="font-weight: bold">, </span>foodImages <span style="font-weight: bold">):
    </span>x<span style="font-weight: bold">, </span>y <span style="font-weight: bold">= </span>cell
    remove_from_screen<span style="font-weight: bold">(</span>foodImages<span style="font-weight: bold">[</span>x<span style="font-weight: bold">][</span>y<span style="font-weight: bold">])

  </span><span style="color: blue; font-weight: bold">def </span>removeCapsule<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>cell<span style="font-weight: bold">, </span>capsuleImages <span style="font-weight: bold">):
    </span>x<span style="font-weight: bold">, </span>y <span style="font-weight: bold">= </span>cell
    remove_from_screen<span style="font-weight: bold">(</span>capsuleImages<span style="font-weight: bold">[(</span>x<span style="font-weight: bold">, </span>y<span style="font-weight: bold">)])

  </span><span style="color: blue; font-weight: bold">def </span>drawExpandedCells<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>cells<span style="font-weight: bold">):
    </span><span style="color: darkred">"""
    Draws an overlay of expanded grid positions for search agents
    """
    </span>n <span style="font-weight: bold">= </span>float<span style="font-weight: bold">(</span>len<span style="font-weight: bold">(</span>cells<span style="font-weight: bold">))
    </span>baseColor <span style="font-weight: bold">= [</span><span style="color: red">1.0</span><span style="font-weight: bold">, </span><span style="color: red">0.0</span><span style="font-weight: bold">, </span><span style="color: red">0.0</span><span style="font-weight: bold">]
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>clearExpandedCells<span style="font-weight: bold">()
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>expandedCells <span style="font-weight: bold">= []
    </span><span style="color: blue; font-weight: bold">for </span>k<span style="font-weight: bold">, </span>cell <span style="color: blue; font-weight: bold">in </span>enumerate<span style="font-weight: bold">(</span>cells<span style="font-weight: bold">):
       </span>screenPos <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>to_screen<span style="font-weight: bold">( </span>cell<span style="font-weight: bold">)
       </span>cellColor <span style="font-weight: bold">= </span>formatColor<span style="font-weight: bold">(*[(</span>n<span style="font-weight: bold">-</span>k<span style="font-weight: bold">) * </span>c <span style="font-weight: bold">* .</span><span style="color: red">5 </span><span style="font-weight: bold">/ </span>n <span style="font-weight: bold">+ .</span><span style="color: red">25 </span><span style="color: blue; font-weight: bold">for </span>c <span style="color: blue; font-weight: bold">in </span>baseColor<span style="font-weight: bold">])
       </span>block <span style="font-weight: bold">= </span>square<span style="font-weight: bold">(</span>screenPos<span style="font-weight: bold">,
                </span><span style="color: red">0.5 </span><span style="font-weight: bold">* </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>gridSize<span style="font-weight: bold">,
                </span>color <span style="font-weight: bold">= </span>cellColor<span style="font-weight: bold">,
                </span>filled <span style="font-weight: bold">= </span><span style="color: red">1</span><span style="font-weight: bold">, </span>behind<span style="font-weight: bold">=</span><span style="color: red">2</span><span style="font-weight: bold">)
       </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>expandedCells<span style="font-weight: bold">.</span>append<span style="font-weight: bold">(</span>block<span style="font-weight: bold">)
       </span><span style="color: blue; font-weight: bold">if </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>frameTime <span style="font-weight: bold">&lt; </span><span style="color: red">0</span><span style="font-weight: bold">:
         </span>refresh<span style="font-weight: bold">()

  </span><span style="color: blue; font-weight: bold">def </span>clearExpandedCells<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">):
    </span><span style="color: blue; font-weight: bold">if </span><span style="color: red">'expandedCells' </span><span style="color: blue; font-weight: bold">in </span>dir<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">and </span>len<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>expandedCells<span style="font-weight: bold">) &gt; </span><span style="color: red">0</span><span style="font-weight: bold">:
      </span><span style="color: blue; font-weight: bold">for </span>cell <span style="color: blue; font-weight: bold">in </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>expandedCells<span style="font-weight: bold">:
        </span>remove_from_screen<span style="font-weight: bold">(</span>cell<span style="font-weight: bold">)


  </span><span style="color: blue; font-weight: bold">def </span>updateDistributions<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>distributions<span style="font-weight: bold">):
    </span><span style="color: red">"Draws an agent's belief distributions"
    </span><span style="color: blue; font-weight: bold">if </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>distributionImages <span style="font-weight: bold">== </span><span style="color: blue">None</span><span style="font-weight: bold">:
      </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>drawDistributions<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>previousState<span style="font-weight: bold">)
    </span><span style="color: blue; font-weight: bold">for </span>x <span style="color: blue; font-weight: bold">in </span>range<span style="font-weight: bold">(</span>len<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>distributionImages<span style="font-weight: bold">)):
      </span><span style="color: blue; font-weight: bold">for </span>y <span style="color: blue; font-weight: bold">in </span>range<span style="font-weight: bold">(</span>len<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">.</span>distributionImages<span style="font-weight: bold">[</span><span style="color: red">0</span><span style="font-weight: bold">])):
        </span>image <span style="font-weight: bold">= </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>distributionImages<span style="font-weight: bold">[</span>x<span style="font-weight: bold">][</span>y<span style="font-weight: bold">]
        </span>weights <span style="font-weight: bold">= [</span>dist<span style="font-weight: bold">[ (</span>x<span style="font-weight: bold">,</span>y<span style="font-weight: bold">) ] </span><span style="color: blue; font-weight: bold">for </span>dist <span style="color: blue; font-weight: bold">in </span>distributions<span style="font-weight: bold">]

        </span><span style="color: blue; font-weight: bold">if </span>sum<span style="font-weight: bold">(</span>weights<span style="font-weight: bold">) != </span><span style="color: red">0</span><span style="font-weight: bold">:
          </span><span style="color: blue; font-weight: bold">pass
        </span><span style="color: green; font-style: italic"># Fog of war
        </span>color <span style="font-weight: bold">= [</span><span style="color: red">0.0</span><span style="font-weight: bold">,</span><span style="color: red">0.0</span><span style="font-weight: bold">,</span><span style="color: red">0.0</span><span style="font-weight: bold">]
        </span>colors <span style="font-weight: bold">= </span>GHOST_VEC_COLORS<span style="font-weight: bold">[</span><span style="color: red">1</span><span style="font-weight: bold">:] </span><span style="color: green; font-style: italic"># With Pacman
        </span><span style="color: blue; font-weight: bold">if </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>capture<span style="font-weight: bold">: </span>colors <span style="font-weight: bold">= </span>GHOST_VEC_COLORS
        <span style="color: blue; font-weight: bold">for </span>weight<span style="font-weight: bold">, </span>gcolor <span style="color: blue; font-weight: bold">in </span>zip<span style="font-weight: bold">(</span>weights<span style="font-weight: bold">, </span>colors<span style="font-weight: bold">):
          </span>color <span style="font-weight: bold">= [</span>min<span style="font-weight: bold">(</span><span style="color: red">1.0</span><span style="font-weight: bold">, </span>c <span style="font-weight: bold">+ </span><span style="color: red">0.95 </span><span style="font-weight: bold">* </span>g <span style="font-weight: bold">* </span>weight <span style="font-weight: bold">** .</span><span style="color: red">3</span><span style="font-weight: bold">) </span><span style="color: blue; font-weight: bold">for </span>c<span style="font-weight: bold">,</span>g <span style="color: blue; font-weight: bold">in </span>zip<span style="font-weight: bold">(</span>color<span style="font-weight: bold">, </span>gcolor<span style="font-weight: bold">)]
        </span>changeColor<span style="font-weight: bold">(</span>image<span style="font-weight: bold">, </span>formatColor<span style="font-weight: bold">(*</span>color<span style="font-weight: bold">))
    </span>refresh<span style="font-weight: bold">()

</span><span style="color: blue; font-weight: bold">class </span>FirstPersonPacmanGraphics<span style="font-weight: bold">(</span>PacmanGraphics<span style="font-weight: bold">):
  </span><span style="color: blue; font-weight: bold">def </span>__init__<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>zoom <span style="font-weight: bold">= </span><span style="color: red">1.0</span><span style="font-weight: bold">, </span>showGhosts <span style="font-weight: bold">= </span><span style="color: blue; font-weight: bold">True</span><span style="font-weight: bold">, </span>capture <span style="font-weight: bold">= </span><span style="color: blue; font-weight: bold">False</span><span style="font-weight: bold">, </span>frameTime<span style="font-weight: bold">=</span><span style="color: red">0</span><span style="font-weight: bold">):
    </span>PacmanGraphics<span style="font-weight: bold">.</span>__init__<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>zoom<span style="font-weight: bold">, </span>frameTime<span style="font-weight: bold">=</span>frameTime<span style="font-weight: bold">)
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>showGhosts <span style="font-weight: bold">= </span>showGhosts
    <span style="color: blue">self</span><span style="font-weight: bold">.</span>capture <span style="font-weight: bold">= </span>capture

  <span style="color: blue; font-weight: bold">def </span>initialize<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>state<span style="font-weight: bold">, </span>isBlue <span style="font-weight: bold">= </span><span style="color: blue; font-weight: bold">False</span><span style="font-weight: bold">):

    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>isBlue <span style="font-weight: bold">= </span>isBlue
    PacmanGraphics<span style="font-weight: bold">.</span>startGraphics<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>state<span style="font-weight: bold">)
    </span><span style="color: green; font-style: italic"># Initialize distribution images
    </span>walls <span style="font-weight: bold">= </span>state<span style="font-weight: bold">.</span>layout<span style="font-weight: bold">.</span>walls
    dist <span style="font-weight: bold">= []
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>layout <span style="font-weight: bold">= </span>state<span style="font-weight: bold">.</span>layout

    <span style="color: green; font-style: italic"># Draw the rest
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>distributionImages <span style="font-weight: bold">= </span><span style="color: blue">None  </span><span style="color: green; font-style: italic"># initialize lazily
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>drawStaticObjects<span style="font-weight: bold">(</span>state<span style="font-weight: bold">)
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>drawAgentObjects<span style="font-weight: bold">(</span>state<span style="font-weight: bold">)

    </span><span style="color: green; font-style: italic"># Information
    </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>previousState <span style="font-weight: bold">= </span>state

  <span style="color: blue; font-weight: bold">def </span>lookAhead<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>config<span style="font-weight: bold">, </span>state<span style="font-weight: bold">):
    </span><span style="color: blue; font-weight: bold">if </span>config<span style="font-weight: bold">.</span>getDirection<span style="font-weight: bold">() == </span><span style="color: red">'Stop'</span><span style="font-weight: bold">:
      </span><span style="color: blue; font-weight: bold">return
    else</span><span style="font-weight: bold">:
      </span><span style="color: blue; font-weight: bold">pass
      </span><span style="color: green; font-style: italic"># Draw relevant ghosts
      </span>allGhosts <span style="font-weight: bold">= </span>state<span style="font-weight: bold">.</span>getGhostStates<span style="font-weight: bold">()
      </span>visibleGhosts <span style="font-weight: bold">= </span>state<span style="font-weight: bold">.</span>getVisibleGhosts<span style="font-weight: bold">()
      </span><span style="color: blue; font-weight: bold">for </span>i<span style="font-weight: bold">, </span>ghost <span style="color: blue; font-weight: bold">in </span>enumerate<span style="font-weight: bold">(</span>allGhosts<span style="font-weight: bold">):
        </span><span style="color: blue; font-weight: bold">if </span>ghost <span style="color: blue; font-weight: bold">in </span>visibleGhosts<span style="font-weight: bold">:
          </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>drawGhost<span style="font-weight: bold">(</span>ghost<span style="font-weight: bold">, </span>i<span style="font-weight: bold">)
        </span><span style="color: blue; font-weight: bold">else</span><span style="font-weight: bold">:
          </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>currentGhostImages<span style="font-weight: bold">[</span>i<span style="font-weight: bold">] = </span><span style="color: blue">None

  </span><span style="color: blue; font-weight: bold">def </span>getGhostColor<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>ghost<span style="font-weight: bold">, </span>ghostIndex<span style="font-weight: bold">):
    </span><span style="color: blue; font-weight: bold">return </span>GHOST_COLORS<span style="font-weight: bold">[</span>ghostIndex<span style="font-weight: bold">]

  </span><span style="color: blue; font-weight: bold">def </span>getPosition<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>ghostState<span style="font-weight: bold">):
    </span><span style="color: blue; font-weight: bold">if not </span><span style="color: blue">self</span><span style="font-weight: bold">.</span>showGhosts <span style="color: blue; font-weight: bold">and not </span>ghostState<span style="font-weight: bold">.</span>isPacman <span style="color: blue; font-weight: bold">and </span>ghostState<span style="font-weight: bold">.</span>getPosition<span style="font-weight: bold">()[</span><span style="color: red">1</span><span style="font-weight: bold">] &gt; </span><span style="color: red">1</span><span style="font-weight: bold">:
      </span><span style="color: blue; font-weight: bold">return </span><span style="font-weight: bold">(-</span><span style="color: red">1000</span><span style="font-weight: bold">, -</span><span style="color: red">1000</span><span style="font-weight: bold">)
    </span><span style="color: blue; font-weight: bold">else</span><span style="font-weight: bold">:
      </span><span style="color: blue; font-weight: bold">return </span>PacmanGraphics<span style="font-weight: bold">.</span>getPosition<span style="font-weight: bold">(</span><span style="color: blue">self</span><span style="font-weight: bold">, </span>ghostState<span style="font-weight: bold">)

</span><span style="color: blue; font-weight: bold">def </span>add<span style="font-weight: bold">(</span>x<span style="font-weight: bold">, </span>y<span style="font-weight: bold">):
  </span><span style="color: blue; font-weight: bold">return </span><span style="font-weight: bold">(</span>x<span style="font-weight: bold">[</span><span style="color: red">0</span><span style="font-weight: bold">] + </span>y<span style="font-weight: bold">[</span><span style="color: red">0</span><span style="font-weight: bold">], </span>x<span style="font-weight: bold">[</span><span style="color: red">1</span><span style="font-weight: bold">] + </span>y<span style="font-weight: bold">[</span><span style="color: red">1</span><span style="font-weight: bold">])


</span><span style="color: green; font-style: italic"># Saving graphical output
# -----------------------
# Note: to make an animated gif from this postscript output, try the command:
# convert -delay 7 -loop 1 -compress lzw -layers optimize frame* out.gif
# convert is part of imagemagick (freeware)

</span>SAVE_POSTSCRIPT <span style="font-weight: bold">= </span><span style="color: blue; font-weight: bold">False
</span>POSTSCRIPT_OUTPUT_DIR <span style="font-weight: bold">= </span><span style="color: red">'frames'
</span>FRAME_NUMBER <span style="font-weight: bold">= </span><span style="color: red">0
</span><span style="color: blue; font-weight: bold">import </span>os

<span style="color: blue; font-weight: bold">def </span>saveFrame<span style="font-weight: bold">():
  </span><span style="color: red">"Saves the current graphical output as a postscript file"
  </span><span style="color: blue; font-weight: bold">global </span>SAVE_POSTSCRIPT<span style="font-weight: bold">, </span>FRAME_NUMBER<span style="font-weight: bold">, </span>POSTSCRIPT_OUTPUT_DIR
  <span style="color: blue; font-weight: bold">if not </span>SAVE_POSTSCRIPT<span style="font-weight: bold">: </span><span style="color: blue; font-weight: bold">return
  if not </span>os<span style="font-weight: bold">.</span>path<span style="font-weight: bold">.</span>exists<span style="font-weight: bold">(</span>POSTSCRIPT_OUTPUT_DIR<span style="font-weight: bold">): </span>os<span style="font-weight: bold">.</span>mkdir<span style="font-weight: bold">(</span>POSTSCRIPT_OUTPUT_DIR<span style="font-weight: bold">)
  </span>name <span style="font-weight: bold">= </span>os<span style="font-weight: bold">.</span>path<span style="font-weight: bold">.</span>join<span style="font-weight: bold">(</span>POSTSCRIPT_OUTPUT_DIR<span style="font-weight: bold">, </span><span style="color: red">'frame_%08d.ps' </span><span style="font-weight: bold">% </span>FRAME_NUMBER<span style="font-weight: bold">)
  </span>FRAME_NUMBER <span style="font-weight: bold">+= </span><span style="color: red">1
  </span>writePostscript<span style="font-weight: bold">(</span>name<span style="font-weight: bold">) </span># writes the current canvas
  </pre>
  </body>
  </html>
  